﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

using nplJobsCommon.Common;

namespace nplJobsDAL.Select
{
    public class SelectLanguage: DataAccessBase
    {
        public SelectLanguage()
        {
            StoredProcedureName = StoredProcedure.Name.spSelectLanguage.ToString();
        }

        #region GetLanguage
        public List<Language> GetLanguage()
        {
            DataBaseHelper dbHelper;
            DataSet dsLanguage;

            try
            {
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dsLanguage = dbHelper.Run(base.ConnectionString);
                return GetList(dsLanguage);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region GetList
        private List<Language> GetList(DataSet dsLanguage)
        {
            List<Language> languages;
            try
            {
                languages = (from n in dsLanguage.Tables[0].AsEnumerable()
                                select new Language
                                   {
                                       ID = n.Field<int>("ID"),
                                       Name = n.Field<string>("Name")
                                   }).ToList();

                return languages;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion
    }
}
